

const reg_var = /\{\{(.*?)\}\}/g    //正则表达式有问题<h2>{{count}}</h2><h1>{{mount}}</h1>

const reg_FrontTag = (node)=>{
    return new RegExp(`\<(.*?)\>${node}\</.*?\>`)
}
const reg_data_dom=/\<.*?\>\{\{(.*?)\}\}<\/.*?\>/
const reg_tag = /\<(\w\d)/
let statePool  = []
function stateFormat (template, state){  
    const _state = {}   
    template= template.replace(reg_data_dom, (node,key)=>{
       
        const matched = node.match(reg_tag)       
        const _flag =parseInt(Math.random()*1000000000)

        _state._flag = _flag
        return `<${matched[1]} data-dom="${_flag}">{{${key}}}</${matched[1]}>`
    })
    
    template = template.replace(reg_var, function(node,key){        
          
        let _var = key.trim()      
        const _var_array = _var.split('.')
        let i = 0     
        
        while (i<_var_array.length){           
            _var =  state[_var_array[i]]           
            i ++
        }
       _state.state = _var_array
      
       statePool.push(_state)     

       return _var       
    })  
  
    return template
}


export {
    stateFormat,
    statePool
}